package com.jilian.powerstation.modul.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jilian.powerstation.R;
import com.jilian.powerstation.common.dto.TemperatureDto;
import com.jilian.powerstation.listener.CustomItemClickListener;
import com.jilian.powerstation.utils.IconUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import interfaces.heweather.com.interfacesmodule.bean.weather.hourly.HourlyBase;

public class TemperatureListAdapter extends RecyclerView.Adapter<TemperatureListAdapter.ViewHolder> {

    private List<HourlyBase> mDatas;
    private Context mContext;
    private CustomItemClickListener listener;

    public TemperatureListAdapter(List<HourlyBase> mDatas, Context context, CustomItemClickListener listener) {
        this.mDatas = mDatas;
        this.mContext = context;
        this.listener = listener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.item_temperature, parent, false);
        ViewHolder viewHolder = new ViewHolder(view, listener);
        return viewHolder;


    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        HourlyBase dto = mDatas.get(position);
        holder.tvTitle.setText(dto.getTime().substring(11));
        holder.tvTem.setText(dto.getTmp() + "°C");
        holder.powerStationCover.setImageResource(IconUtils.getDayIconDark(dto.getCond_code()));

    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvTitle;
        private ImageView powerStationCover;
        private TextView tvTem;


        public ViewHolder(@NonNull View itemView, final CustomItemClickListener listener) {
            super(itemView);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
            powerStationCover = (ImageView) itemView.findViewById(R.id.power_station_cover);
            tvTem = (TextView) itemView.findViewById(R.id.tv_tem);
        }
    }


}
